# Brain dump

Using SDKMAN! to manage your Java and Spring Boot installations is a great choice. Below are the steps to create a simple Spring Boot application that serves a Velocity template for the homepage, using SDKMAN! for setup.

### Step 1: Install SDKMAN!

If you haven't installed SDKMAN! yet, you can do so by running the following command in your terminal:

```bash
curl -s "https://get.sdkman.io" | bash
```

After installation, you may need to restart your terminal or run:

```bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
```

### Step 2: Install Java and Maven

Use SDKMAN! to install Java and Maven:

```bash
sdk install java 17.0.2-open
sdk install maven
```

### Step 3: Create a New Spring Boot Project

You can create a new Spring Boot project using the Spring Initializr. You can do this directly from the command line using `curl`:

```bash
curl https://start.spring.io/starter.zip -d dependencies=web,velocity -d name=demo -d packageName=com.example.demo -o demo.zip
```

Unzip the downloaded file:

```bash
unzip demo.zip
cd demo
```

### Step 4: Update `pom.xml`

Make sure your `pom.xml` includes the necessary dependencies for Spring Boot and Apache Velocity. Here’s a minimal example:

```xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
        <spring-boot.version>2.7.0</spring-boot.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-velocity</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
```

### Step 5: Create the Main Application Class

Create a file named `DemoApplication.java` in the `com.example.demo` package:

```java
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
```

### Step 6: Create the Home Controller

Create a file named `HomeController.java` in the `com.example.demo.controller` package:

```java
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    @GetMapping("/")
    public String home(Model model) {
        model.addAttribute("message", "Welcome to the Velocity Template Example!");
        return "home"; // This refers to home.vm
    }
}
```

### Step 7: Create the Velocity Template

Create a directory named `templates` under `src/main/resources`, and then create a file named `home.vm` inside it:

```velocity
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
</head>
<body>
    <h1>$message</h1>
</body>
</html>
```

### Step 8: Run the Application

You can run your Spring Boot application using Maven. In the terminal, navigate to the root of your project and run:

```bash
./mvnw
